<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
            "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>



<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="hevea 1.08">
<LINK rel="stylesheet" type="text/css" href="umsroot.css">
<TITLE>
Altering programs at run time
</TITLE>
</HEAD>
<BODY >
<A HREF="umsroot063.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="umsroot062.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<A HREF="umsroot065.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
<HR>

<H2 CLASS="section"><A NAME="htoc161">11.2</A>&nbsp;&nbsp;Altering programs at run time</H2>
The Prolog database can be updated during the execution of a program.
<A NAME="@default635"></A>
ECL<SUP><I>i</I></SUP>PS<SUP><I>e</I></SUP> allows the user to modify procedures dynamically by adding
new clauses via <A HREF="../bips/kernel/dynamic/assert-1.html"><B>assert/1</B></A><A NAME="@default636"></A> and by removing some clauses via <A HREF="../bips/kernel/dynamic/retract-1.html"><B>retract/1</B></A><A NAME="@default637"></A>.
<A NAME="@default638"></A>
<A NAME="@default639"></A>
These predicates operate on dynamic procedures; if it is
required that the definition of a procedure be altered through
assertion and retraction, the procedure should therefore first be declared
dynamic (see the previous section). The effect of <A HREF="../bips/kernel/dynamic/assert-1.html"><B>assert/1</B></A><A NAME="@default640"></A> and
<A HREF="../bips/kernel/dynamic/retract-1.html"><B>retract/1</B></A><A NAME="@default641"></A> on static procedures is explained below.<BR>
<BR>
The effect of the goal
<BLOCKQUOTE CLASS="quote">
<PRE CLASS="verbatim">
assert(ProcClause)
</PRE></BLOCKQUOTE>
where
<TT>ProcClause</TT><SUP><A NAME="text15" HREF="umsroot062.html#note15">1</A></SUP>
is a clause of the procedure <TT>Proc</TT>, is as follows.
<OL CLASS="enumerate" type=1><LI CLASS="li-enumerate">
If <TT>Proc</TT> has not been previously defined, the assertion
raises an exception, however the default handler for this exception
just declares the given procedure silently as dynamic and executes
the assertion.<BR>
<BR>
<LI CLASS="li-enumerate">If <TT>Proc</TT> is already defined as a dynamic procedure,
the assertion adds <I>ProcClause</I>
to the database after any clauses already existing for <TT>Proc</TT>.<BR>
<BR>
<LI CLASS="li-enumerate">If <TT>Proc</TT> is already defined as a static procedure, then the assertion
raises an exception.
</OL>
The goal 
<BLOCKQUOTE CLASS="quote">
<PRE CLASS="verbatim">
retract(Clause)
</PRE></BLOCKQUOTE>
will unify <TT>Clause</TT> with a clause on the dynamic database and remove it.
If <TT>Clause</TT> does not specify a dynamic procedure, an exception is raised.<BR>
<BR>
<A NAME="@default642"></A>
ECL<SUP><I>i</I></SUP>PS<SUP><I>e</I></SUP>'s dynamic database features the so-called <I>logical update semantics</I>.
This means that any change in the database that occurs as a result of
executing one of the builtins of the abolish, assert or retract family
affects only those goals that start executing
afterwards. For every call to a dynamic procedure, the procedure is
virtually frozen at call time.<BR>
<BR>
<HR>
<A HREF="umsroot063.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="umsroot062.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<A HREF="umsroot065.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
</BODY>
</HTML>
